package cn.xmkeshe.dao;

import cn.xmkeshe.model.Admin;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface IAdminDao {

  @Select("select * from admin where aid=#{aid}")
  public Admin findById(String aid);

  @Update("UPDATE admin SET password=#{password} WHERE aid=#{aid}")
  public boolean doUpdateByPassword(@Param("aid") String aid, @Param("password") String password);

  //  分页查询
  @Select("select * from admin LIMIT #{start},#{lineSize}")
  public List<Admin> findAllSplit(Map<String,Object> params);

  //  统计数量
  @Select("select COUNT(aid) from admin")
  public Integer getAllCount();

  @Insert("INSERT INTO admin(aid,password,name,photo)VALUES(#{aid},#{password},#{name},#{photo})")
  public boolean doCreate(Admin admin);

  @Insert("INSERT INTO admin_role(aid,rid)VALUES(#{aid},#{rid})")
  public boolean doCreateAdminByRole(Map<String,Object> params);

//  记录最后一次登录
  @Update("UPDATE admin set lastdate = #{lastdate} WHERE aid = #{aid}")
  public boolean doUpdateByLastdate(@Param("aid") String aid,@Param("lastdate") Date lastdate);

  @Select("SELECT * FROM admin where name like #{name} LIMIT #{currentPage},#{lineSize}")
  public List<Admin> findByName(@Param("currentPage") int currentPage, @Param("lineSize") int lineSize,@Param("name") String name);

}
